package com.gps.misc;



import android.graphics.Bitmap;

import com.datatypes.GeoPtr;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

public class MapToBitMap {

	double maxLatitude, minLatitude;
	double maxLongitude, minLongitude;

	public MapToBitMap(GeoPtr gpt) {
		maxLatitude = gpt.getLatitude();
		minLatitude = gpt.getLatitude();

		maxLongitude = gpt.getLongitude();
		minLongitude = gpt.getLongitude();
	}

	public void updateMinMax(GeoPtr gpt) {

		if (gpt.getLatitude() > maxLatitude)
			maxLatitude = gpt.getLatitude();
		else if (gpt.getLatitude() < minLatitude)
			minLatitude = gpt.getLatitude();

		if (gpt.getLongitude() > maxLongitude)
			maxLongitude = gpt.getLongitude();
		else if (gpt.getLongitude() < minLongitude)
			minLongitude = gpt.getLongitude();
	}

	public void centerMap(MapController contorller) {
		contorller.animateTo(new GeoPoint(
				(int) ((maxLatitude + minLatitude) * 1E6 / 2),
				(int) ((maxLongitude + minLongitude) * 1E6 / 2)));
	}

	public Bitmap toBitMap(MapView map) {

		map.setDrawingCacheEnabled(true);
		Bitmap b = map.getDrawingCache();

		/** saves the image on the sdcard **/
		/*
		 * File sdCard = Environment.getExternalStorageDirectory(); File file =
		 * new File(sdCard, "image.jpg"); try { FileOutputStream fos = new
		 * FileOutputStream(file); b.compress(CompressFormat.JPEG, 95,fos); }
		 * catch (FileNotFoundException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); }
		 */

		return b;

	}

}
